package cn.tedu.egweibo05.base.expection;

import cn.tedu.egweibo05.base.response.JsonResult;
import cn.tedu.egweibo05.base.response.StatusCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler
    public JsonResult doHandleMethodArgumentNotValidException(MethodArgumentNotValidException ex) {
        log.debug("方法参数校验异常：{}", ex.getMessage());
        return new JsonResult(StatusCode.VALIDATE_FAILED, ex.getFieldError().getDefaultMessage());
    }
}
